#!/usr/local/bin/python

import os
import sys
import operator
import time
from pwd import getpwuid

if len(sys.argv) == 2:
    _dir = sys.argv[1]
else:
    _dir = raw_input("Please enter the file path: ")

users_dic = {}

######### Recursion ##########

def search_space(dir_path):
    dir_files = os.listdir(dir_path)
    for token in dir_files:
         if os.path.isfile(dir_path + "/" + token):
             #print token
             file_size = os.stat(dir_path + "/" + token).st_size
             #print file_size
             user_id = getpwuid(os.stat(dir_path + "/" + token).st_uid).pw_name
             #print user_id
             if user_id in users_dic.keys():
                 users_dic[user_id] += file_size
             else:
                 users_dic[user_id] = file_size
         else:
             search_space(dir_path + "/" + token)

############################################

search_space(_dir)
sorted_users = sorted(users_dic.items(), key=operator.itemgetter(1))
print "Most consuming users : "

i = 0
for item in sorted_users:
    if i<10:
        print "User " + str(item[0])
        i += 1
    else:
        break
